-- @owner:songfei_st
-- @date:2024-5-27
-- @testpoint:1.合理报错，关闭预编译参数，创建带有rowtype的触发器,部分用例合理报错          


--创建一个表，用来存需验证的数据
create table t_Compare_Case0029(id int,first_name varchar(100), last_name varchar(100));

--step1:关闭预编译参数
set behavior_compat_options='';

--step2:创建表;expect:成功
create table t_CurRowtype_PLObject_Case0029(first_name varchar(100), last_name varchar(100));
insert into t_CurRowtype_PLObject_Case0029 values('Jason','Statham');

--step3:创建带有rowtype的触发器函数;expect:成功
create or replace function f_CurRowtype_PLObject_Case0029() returns trigger as
$$
declare
  cursor cur_1 is select * from t_CurRowtype_PLObject_Case0029;
  source cur_1%rowtype;
  source1 cur_1%rowtype;
begin
   source.first_name:=new.first_name;
   source.last_name:=new.last_name;
   source1 := new;   
   insert into t_Compare_Case0029(first_name,last_name) values (source.first_name,source.last_name);
   insert into t_Compare_Case0029(first_name,last_name) values (source1.first_name,source1.last_name);
   return new;
end
$$ language plpgsql;
/

--step4:创建INSERT触发器;expect:成功
create trigger tri_CurRowtype_PLObject_Case0029 before insert on t_CurRowtype_PLObject_Case0029 for each row
execute procedure f_CurRowtype_PLObject_Case0029();
/

--step5:调用触发器;expect:成功
insert into t_CurRowtype_PLObject_Case0029 values('Jason_New','Statham_New');
insert into t_CurRowtype_PLObject_Case0029 values(null,null);

--step6:查询数据;expect:成功,4行数据
select * from t_Compare_Case0029 order by 1;

--清理环境;expect:成功(4 rows)
drop trigger tri_currowtype_plobject_case0029 on t_CurRowtype_PLObject_Case0029;
drop function f_CurRowtype_PLObject_Case0029;
drop table t_Compare_Case0029;
drop table t_CurRowtype_PLObject_Case0029;
--重置参数
reset all;